package com.xi.vo;

import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.Objects;

/**
 * 通用返回
 *
 * @param <T> 数据泛型
 */
@Data
public class CommonResult<T> implements Serializable {
    private Integer code;

    private T data;

    private String msg;

    private Long duration;

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<>();
        result.code = 200;
        result.data = data;
        result.msg = "success";
        return result;
    }

    public static CommonResult<JSONObject> successObject() {
        CommonResult<JSONObject> result = new CommonResult<>();
        result.code = 200;
        result.data = new JSONObject();
        result.msg = "success";
        return result;
    }
}
